package impl;

import java.io.DataInputStream;
import java.io.IOException;

public class SenderThread extends Thread{
	private Sender client;
	private DataInputStream input;
	private String prompt;
	
	public SenderThread(Sender client, DataInputStream input){
		this.client = client;
		this.input = input;
		
		start();
	}
	
	// With the thread running the background this method will read all message
	// sent from other clients and display them in the console
	public void run() {
		try {
			while (client.isConnect()) {
				String message = input.readUTF();
				if (message != null && !message.equals("")) {
					System.out.println();
					System.out.println(prompt + message);
				}
			}
			//if the user has selected to logout then return from the Thread to stop it from checking for messages
			return;
		} catch (IOException e) {
			System.out.println(e.getStackTrace());
		}
	}
}
